import http from '@ohos.net.http';
export function requestUrl( url:string,callback:(result)=>void ){
  let httpRequest = http.createHttp(); //创建请求对象
  let requestOptions = { // 请求配置选项
    method: http.RequestMethod.POST,
    header: {
      'Content-Type': 'application/json'
    },
    connectTimeout: 30000, // 连接超时时间
    readTimeout: 30000, // 读取数据超时时间
  }
  // 订阅HTTP Response Header 事件
  httpRequest.on('headersReceive', (header) => {
    console.info('header: ' + JSON.stringify(header));
  });
  // 发起HTTP网络请求
  let res = httpRequest.request(url, requestOptions);
  // 异步处理结果
  res.then((data) => {
    callback(data.result) // 返回数据后回调
  }).catch((err) => {
    httpRequest.destroy(); // 销毁
  });
}